<template>
    <div>
        <van-tabs v-model="active" @click="tapTab">
            <van-tab :title="tab.title" v-for="(tab,index) in tabList" :key="index"></van-tab>
        </van-tabs>
        <div>
            <better-scroll
                ref="scroll"
                class="scroll-t"
                :refresh="initDataList"
                :onLoading="loadDataList"
                :isCategory="false">
                <div class="pro-goods-items flex-row plr15">
                    <div class="pro-goods-item" v-for="(item, index) in loadData"
                         @click="$router.push({name:'gift-detail',query:{id:item.id}})">
                        <img class="pro-goods-pic" :src="item.img" alt="">
                        <div class="pro-goods-main">
                            <h4 class="pro-goods-title row1">{{item.name}}</h4>
                            <p class="pro-goods-info">
                                <span class="pro-goods-price">¥{{computePrice(item.amount)}}</span>
                            </p>
                        </div>
                    </div>
                </div>
            </better-scroll>
        </div>
    </div>
</template>

<script>
    export default {
        name: "giftList",
        data() {
            return {
                active: 0,
                tabList: [
                    {title: '店主礼包', type: 0},
                    {title: '合伙人礼包', type: 1},
                    {title: '升级礼包', type: 2},
                ],
                params: {type: '', offset: 0, len: 10}

            }
        },
        beforeRouteEnter(to, from, next) {
            next(vm => {
                if (from.name !== 'goods-detail') vm.initDataList()

            })
        },
        methods: {
            tapTab() {
                this.initDataList()
            },
            initParams() {
                this.params.offset = 0
                this.loadData = []
            },
            initDataList() {
                this.initParams()
                this.loadDataList()
            },
            loadDataList() {
                this.params.type = this.active
                this.pubilcInitDataList('GIFT_GOODS_LIST', this.params)
            },
        }
    }
</script>

<style scoped lang="scss">
    .scroll-t {
        top: 92px;
    }

    .pro-goods-items {
        flex-wrap: wrap;
    }

    .pro-goods-item {
        display: flex;
        align-items: center;
        flex-direction: column;
        width: 165px;
        height: 230px;
        margin-top: 10px;
        background: #fff;
        padding: 0 10px;
        border-radius: 5px;
        .pro-goods-pic {
            width: 165px;
            height: 165px;
            border-top-left-radius: 5px;
            border-top-right-radius: 5px;
            margin-bottom: 5px;
        }
        .pro-goods-main {
            width: 100%;
            .pro-goods-title {
                font-size: 13px;
            }
            .pro-goods-info {
                font-size: 12px;
                .pro-goods-price {
                    display: flex;
                    align-items: flex-end;
                    line-height: 1.2;
                    font-size: 14px;
                    margin: 3px 0;
                    color: $theme-color;
                    .pro-goods-o_price {
                        margin-left: 5px;
                        font-size: 12px;
                        color: #999;
                    }
                }
            }
        }
    }
</style>
